package cn.catsdad.page;

import cn.catsdad.base.page.PageParam;
import cn.catsdad.util.StringUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.HashMap;
import java.util.Map;

/**
 * 文件查询参数
 *
 * @author xuyonglong
 * @version V1.0 2023/4/25
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class DocumentParam extends PageParam {

    private Map<String, Object> param = new HashMap<>();

    private Long objectId;

    private String objectKey;

    @Override
    public Map<String, Object> getParamMap() {
        return this.param;
    }

    @Override
    public String getCondition() {
        StringBuilder condition = new StringBuilder(" and d.isDeleted = 0");
        if (objectId != null) {
            condition.append(" and d.objectId = :objId");
            this.param.put("objId", this.objectId);
        }
        if (StringUtil.isNotEmpty(this.objectKey)) {
            condition.append(" and d.objectKey = :key");
            this.param.put("key", this.objectKey);
        }
        return condition.toString();
    }
}
